import { configureStore } from "@reduxjs/toolkit"
import LoginReducer from "./modules/login"

import HomeReducer from "@/views/home/store"
import discoverReducer from "@/views/discover/store"
import discoverPageReducer from "@/views/discoverPage/store"
import playerReducer from "@/views/player/store"
import musicLibraryReducer from "@/views/musicLibrary/store"
import albumReducer from "@/views/album/store"
import artistReducer from "@/views/artist/store"
import playlistReducer from "@/views/playlist/store"

import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"

const store = configureStore({
  reducer: {
    login: LoginReducer,
    home: HomeReducer,
    discover: discoverReducer,
    discoverPage: discoverPageReducer,
    player: playerReducer,
    musicLibrary: musicLibraryReducer,
    album: albumReducer,
    artist: artistReducer,
    playlist: playlistReducer,
  }
})

export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch

export const useAppDispatch = () => useDispatch<AppDispatch>()
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector

export default store